package com.smyh.model.host.state;

import android.content.Context;
import android.graphics.Color;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

import com.smyh.UIM.host.state.HostStateActivity;
import com.smyh.bean.HostState;
import com.smyh.cache.UIM.MainCahce;
import com.smyh.model.tableModel.KtableView;

/**
 * Created by 姜龙 on 2016/7/8.
 */
public class HostModel {

    private static TableLayout tableLayout;

    public static TableLayout getTableLayout(Context context){
        if(tableLayout == null){
            tableLayout = new TableLayout(context);
            tableLayout.setLayoutParams(new TableLayout.LayoutParams(
                    TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.MATCH_PARENT));
            tableLayout.setBackgroundColor(Color.BLACK);
            KtableView.setIsEditColNum(null);
            String header0[] = {"主机参数"};
            String header1[] = {"名称","值","描述"};
            String test1[] = {"信号强度","","信号强度"};
            String test2[] = {"充电电压","","充电电压"};
            String test3[] = {"电池电压","","电池电压"};
            tableLayout.addView(KtableView.addTableHeaders(context,header0));
            tableLayout.addView(KtableView.addTableHeaders(context,header1));
            tableLayout.addView(KtableView.addNewRow(context,test1));
            tableLayout.addView(KtableView.addNewRow(context,test2));
            tableLayout.addView(KtableView.addNewRow(context,test3));
        }
        return tableLayout;
    }

    public static void setTableLayout() {
        for(int i=2;i<tableLayout.getChildCount();i++){
            TableRow childRow = (TableRow) tableLayout.getChildAt(i);
            HostState info = HostStateActivity.infoMap.get(MainCahce.chooseDeviceAddr);
            if (info != null){

                switch (i){
                    case 2 :
                        ((TextView) childRow.getChildAt(1)).setText(info.getSignalIntensity()+"");
                        break;
                    case 3 :
                        ((TextView) childRow.getChildAt(1)).setText(info.getChargeVoltage()+"");
                        break;
                    case 4 :
                        ((TextView) childRow.getChildAt(1)).setText(info.getBatteryElecVolt()+"");
                        break;
                }
            }else {
                switch (i){
                    case 2 :
                        ((TextView) childRow.getChildAt(1)).setText(" ");
                        break;
                    case 3 :
                        ((TextView) childRow.getChildAt(1)).setText(" ");
                        break;
                    case 4 :
                        ((TextView) childRow.getChildAt(1)).setText(" ");
                        break;
                }

            }
        }
    }
}
